package info.webest.media;

import info.webest.media.files.FileFilter;

import java.io.File;
import java.util.HashMap;

import android.util.Log;

@SuppressWarnings("serial")
public class FileItem extends HashMap<String, Object> {

	private boolean checked = false;
	public int childCount = 0;
	public Long Duration;

	// checked
	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public void toggleChecked() {
		checked = !checked;
	}

	// File
	public void setFile(File file) {
		put("file", file);
	}

	public String getTitle() {

		String title = "";
		String fileName = getFileName();

		if (FileFilter.isAudioExt(fileName)) {
			title = fileName.substring(0, (fileName.length() - 4));
		} else {
			title = fileName;
		}
		return title;
	}

	public String getFileName() {
		return getFile().getName();
	}

	public File getFile() {
		return (File) get("file");
	}

	public String getDuration() {
		File f = getFile();
		String result = "";
		if (f.isFile()) {
			String FileName = f.getAbsolutePath();
			try {
				result = MediaMetadata.getDuration(FileName);
			} catch (Exception e) {
				Log.e("ERROR: getDuration()", FileName);
				e.printStackTrace();
			}
		}
		return result;
	}

}
